package ua.com.minus1.lookbattle;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import com.actionbarsherlock.app.SherlockDialogFragment;
import ua.com.minus1.lookbattle.utils.BundleValues;

/**
 * Created with IntelliJ IDEA.
 * User: Igorek
 * Date: 11/2/12
 * Time: 10:42 PM
 * To change this template use File | Settings | File Templates.
 */
public class AddLookDialogFragment extends SherlockDialogFragment implements View.OnClickListener {

    private ImageButton cameraBtn;
    private ImageButton galleryBtn;
    private int mCatId;
    private Callbacks callbacks;

    public static AddLookDialogFragment newInstance(int catIdOnPosition) {
        Bundle args = new Bundle();
        args.putInt(BundleValues.CAT_ID, catIdOnPosition);

        AddLookDialogFragment f = new AddLookDialogFragment();
        f.setArguments(args);
        return f;
    }

    public interface Callbacks {
        void onAddLookDialogSelect(boolean useCamera);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        callbacks = (Callbacks) activity;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mCatId = getArguments().getInt(BundleValues.CAT_ID);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ViewGroup content = (ViewGroup) inflater.inflate(R.layout.fragment_add_look_choose, container, false);
        getDialog().setTitle("Add Look");
        return content;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        cameraBtn = (ImageButton) view.findViewById(R.id.add_look_camera_button);
        cameraBtn.setOnClickListener(this);
        galleryBtn = (ImageButton) view.findViewById(R.id.add_look_gallery_button);
        galleryBtn.setOnClickListener(this);
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.add_look_camera_button:
               callbacks.onAddLookDialogSelect(true);
                //addLook(true);
                break;
            case R.id.add_look_gallery_button:
                //addLook(false);
                callbacks.onAddLookDialogSelect(false);
                break;
        }
        dismiss();
    }

   /* private void addLook(boolean useCamera) {
        Bundle extras = new Bundle();
        extras.putBoolean(BundleValues.USE_CAMERA, useCamera);
        extras.putInt(BundleValues.CAT_ID, mCatId);

        Intent intent = new Intent(getActivity(), AddLookActivity.class);
        intent.putExtras(extras);
        getActivity().startActivity(intent);
    }*/

}
